﻿Imports WINX32Lib
Imports System.IO


Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Sub Get_Parameters(ByRef Args_String As String)
        Args_String = "#Input_File " & TextBox_Input_File.Text & _
                " #Lower_Lewel " & NumericUpDown_Lower_Lewel.Value.ToString & _
                " #Upper_Lewel " & NumericUpDown_Upper_Level.Value.ToString & _
                " #Min_Intensity " & NumericUpDown_Min_Intensity.Value.ToString & _
                " #Lower_Lewel1 " & NumericUpDown_Lower_Lewel1.Value.ToString & _
                " #Upper_Lewel1 " & NumericUpDown_Upper_Level1.Value.ToString & _
                " #Initial_Frame " & NumericUpDown_Initial_Frame.Value.ToString & _
                " #Final_Frame " & NumericUpDown_Final_Frame.Value.ToString & _
                "  "
    End Sub

    Private Sub Button_Input_File_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Input_File.Click
        Dim MyFileOpen As New System.Windows.Forms.OpenFileDialog
        Dim retVal As Windows.Forms.DialogResult
        Dim sMyFiles() As String
        MyFileOpen.Multiselect = True
        retVal = MyFileOpen.ShowDialog()
        If retVal = Windows.Forms.DialogResult.OK Then
            If MyFileOpen.CheckFileExists = True And MyFileOpen.CheckPathExists = True Then
                sMyFiles = MyFileOpen.FileNames

                TextBox_Input_File.Text = ""
                For Each file_name In sMyFiles
                    TextBox_Input_File.Text = TextBox_Input_File.Text & file_name & vbNewLine
                    '%%%% here should be the rutine to check if there are multiple files
                    Dim str As FileStream
                    Dim reader As BinaryReader
                    Dim Obj1 As New ProcInput
                    str = New FileStream(file_name, FileMode.Open)
                    reader = New BinaryReader(str)
                    For ct As Integer = 0 To 2049
                        If ct = 723 Or ct = 328 Or ct = 54 Or ct = 21 Then
                            If ct = 723 Then
                                Obj1.ZEnd = reader.ReadInt16()
                            End If
                            If ct = 328 Then
                                Obj1.YEND = reader.ReadInt16()
                            End If
                            If ct = 54 Then
                                Obj1.dataType = reader.ReadInt16()
                            End If
                            If ct = 21 Then
                                Obj1.XEND = reader.ReadInt16()
                            End If
                        Else
                            reader.ReadInt16()
                        End If
                    Next
                    str.Close()
                    reader.Close()
                    NumericUpDown_Initial_Frame.Value = 1
                    NumericUpDown_Final_Frame.Value = Obj1.ZEnd
                Next
            End If
        End If

    End Sub

End Class